-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
borrowck: consolidate mut
suggestions
#40841
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it (besides a couple of nitpicks).
x: X | ||
} | ||
|
||
fn main() { | ||
pub fn main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn main
?
} | ||
|
||
fn local_ty(&self, node_id: ast::NodeId) -> Option<&hir::Ty> { | ||
let parent = self.tcx.hir.get_parent_node(node_id); | ||
let parent_node = self.tcx.hir.get(parent); | ||
|
||
// The parent node is like a fn | ||
if let Some(fn_like) = FnLikeNode::from_node(parent_node) { | ||
// `nid`'s parent's `Body` | ||
let fn_body = self.tcx.hir.body(fn_like.body()); | ||
// Get the position of `nid` in the arguments list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update comment to node_id
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(let_span) { | ||
if self.tcx.hir.name(node_id) == keywords::SelfValue.name() && | ||
snippet != "self" { | ||
// avoid suggesting `mut &self`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it suggest &mut self
in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. Binding vs. reference - the code is intentionally careful to do the right thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, you're right, of course.
@@ -198,7 +198,7 @@ fn main() { | |||
``` | |||
"##, | |||
|
|||
E0386: r##" | |||
/*E0386: r##" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the procedure to remove Errors that we no longer emit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no such procedure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We put these into register_diagnostics! {}
, commented out, although a better way to annotate codes that may not be reused should be made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nagisa are you saying that this modification (the commenting out here) is okay as is? Or are you saying it shouldn't stay here under register_long_diagnostics!
, and should ... move to register_diagnostics!
...?
I think you must mean the former, that this is okay as is... Let us know if I misunderstand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(well I guess deleting all this long commented-out diagnostic text and replacing it with one line in register_diagnostics!
could be an attractive option...)
Is #35927 supposed to link somewhere else? |
This converts all of borrowck's `mut` suggestions to a new `mc::ImmutabilityBlame` API instead of the current mix of various hacks. Fixes rust-lang#35937. Fixes rust-lang#40823.
86d19dc
to
39011f8
Compare
@whataloadofwhat Indeed. Updated & fixed. BTW, @eddyb & @petrochenkov - is there a cleaner way of determining whether a function has an implicit self? |
@arielb1 Doubt it. It might be better idea to preserve the distinction in |
@bors r+ |
📌 Commit 39011f8 has been approved by |
borrowck: consolidate `mut` suggestions This converts all of borrowck's `mut` suggestions to a new `mc::ImmutabilityBlame` API instead of the current mix of various hacks. Fixes rust-lang#35937. Fixes rust-lang#40823. Fixes rust-lang#40859. cc @estebank r? @pnkfelix
This converts all of borrowck's
mut
suggestions to a newmc::ImmutabilityBlame
API instead of the current mix of various hacks.Fixes #35937.
Fixes #40823.
Fixes #40859.
cc @estebank
r? @pnkfelix